home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Subject: Re: Help to detect error
- Message-ID: <DpqLyB.8J9@rci.ripco.com>
- X-Nntp-Sender: mambuhl@golden.ripco.com
- Sender: usenet@rci.ripco.com (Net News Admin)
- Organization: Ripco Internet BBS Chicago
- Date: Fri, 12 Apr 1996 06:56:35 GMT
-
- bz786@torfree.net (Sherif Asif) in <DpMA82.KEE.0.bloor@torfree.net> asks
- about several errors in his code.
-
- Even though there have been some claims that everyone gets indentation
- "right" and somehow can't handle braces, the lack of indentation in your
- code is a clear counter-example. The indentation has been added in the
- corrections below. As usual, my changes (or other notes) are marked
- with `/* mha - ... */' comments:
-
- #include <stdio.h>
- /*reoder 1 dim array, int array from smallest to largest*/
- int main()
- { /* mha - added explicit return type
- * [optional] */
- int i, n, x[100];
- void reorder(int n, int x[]); /* mha - added return type (so this
- * is now a prototype rather than an
- * erroneous attempt to invoke reorder()
- */
- printf("How many no:\n");
- scanf("%d", &n); /* mha - this is not a good idea. For
- * other choices, get the FAQ from
- * rtfm.mit.edu and read it. */
- printf("\n");
- for (i = 0; i < n; ++i);
- {
- printf("i = %d x = ", i + 1);
- scanf("%d", &x[n]); /* mha - see above */
- }
- reorder(n, x);
- printf("Recorded list of nos:\n\n");
- for (i = 0; i < n; ++i)
- printf("i= %d x=%d\n", i + 1, x[i]);
- return 0; /* mha - added explicit return
- * [optional] */
- }
-
- void reorder(int n, int x[])
- { /* mha - added explicit return type */
- int item, i, temp;
- for (item = 0; item < n - 1; ++item)
- for (i = item + 1; i < n; ++i) /* mha - changed `/' to `)' */
- if (x[i] < x[item]) {
- temp = x[item];
- x[item] = x[i];
- x[i] = temp;
- }
- return;
- }
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-